package com.cskaoyan.wx.vo;

import com.cskaoyan.bean.*;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class GoodsDetailVO {

    @Data
    @AllArgsConstructor
    public static class CommentVO {
        int count;
        List<Comment> data;
    }

    @Data
    @AllArgsConstructor
    public static class SpecificationVO {
        String name;
        List<GoodsSpecification> valueList;
    }

    List<GoodsAttribute> attribute;
    Brand brand;
    CommentVO comment;
    List<GrouponRules> groupon = Collections.emptyList();
    Goods info;
    List<Issue> issue;
    List<GoodsProduct> productList;
    String shareImage = "";
    List<SpecificationVO> specificationList;
    int userHasCollect;

    public void setSpecificationList(List<GoodsSpecification> specifications) {

        Map<String, List<GoodsSpecification>> map = specifications.stream()
                .collect(Collectors.groupingBy(GoodsSpecification::getSpecification));


        this.specificationList = new ArrayList<>(map.size());

        for ( Map.Entry<String, List<GoodsSpecification>> entry: map.entrySet()) {
            this.specificationList.add(new SpecificationVO(entry.getKey(), entry.getValue()));
        }
    }
}
